import 'dart:async';

import 'package:flutter_axrjc/datasource/network/api/UserApi.dart';
import 'package:flutter_axrjc/datasource/network/bean/EventBean.dart';
import 'package:flutter_axrjc/main.dart';
import 'package:get/get.dart';

import 'state.dart';

class MineLogic extends GetxController {
  final MineState state = MineState();
  // final checkLogic = Get.find<CheckManageLogic>();
  StreamSubscription? listener;
  @override
  void onInit() {
    super.onInit();
    loadUser();
    listener = eventBus.on<EventBean>().listen((event) {
      if (event.type == EventType.refreshProfile) {
        loadUser();
      }
    });
  }

  Future<void> loadUser() async {
    state.user.value = await UserApi.getUser();
  }

  @override
  void onClose() {
    super.onClose();
    listener?.cancel();
  }

  void toMyLight() {
    eventBus.fire(EventBean(type: EventType.changeMainPage, data: 1));
    eventBus.fire(EventBean(type: EventType.changeManagePage, data: 0));
  }
}
